from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
import logging

class Greeting(models.Model):
  author = models.ForeignKey(User, null=True, blank=True)
  content = models.TextField()
  date = models.DateTimeField(auto_now_add=True)
    

class Bar(models.Model):
  name = models.CharField(max_length=200)
  description = models.TextField()
  address = models.TextField()
  picturePath = models.CharField(max_length=255)
  latitude = models.CharField(max_length=30)
  longitude = models.CharField(max_length=30)
  adminLogin = models.ForeignKey(User, related_name='+', null=True )

class UserProfile(models.Model):
  user = models.OneToOneField(User)
  aboutMe = models.TextField()
  
class Deal(models.Model):
  user = models.ForeignKey(User, related_name='+')
  usedDate = models.DateTimeField(null=True)
  bar = models.ForeignKey(Bar, null=True)
  status = models.IntegerField()
  price = models.FloatField()
  
class Logs(models.Model):
  username = models.CharField(max_length=100)
  date = models.DateTimeField(auto_now_add=True)
  ipAdress = models.CharField(max_length=100)
  page = models.CharField(max_length=200)
  action = models.CharField(max_length=100)
  description = models.TextField()

class Transaction(models.Model):
  user = models.ForeignKey(User, related_name='+')
  trxId = models.CharField(max_length=200)
  token = models.CharField(max_length=100)
  price = models.CharField(max_length=100)
  numberOfDeal = models.SmallIntegerField()
  status = models.CharField(max_length=100)
    
class Price(models.Model):
  nbCoupon = models.CharField(max_length=100)
  price = models.CharField(max_length=100)
  
  
def create_user_profile(sender, instance, created, **kwargs):
  logging.debug('create_user_profile')
  if created:
    UserProfile.objects.create(user=instance)

post_save.connect(create_user_profile, sender=User)
